﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;


namespace SLNavigate2
{
    /// <summary>
    /// Facade used to resolve data and resource contexts for
    /// Edge Smooth Streaming.
    /// </summary>
    public sealed class ContextManager
    {
        #region data
        private object _sync;
        private static readonly ContextManager _instance = new ContextManager();
        private BaseViewModel _vm;
        #endregion


        #region singleton access and creation
        /// <summary>
        /// Initializes a new instance of the <see cref="ContextManager"/> class.
        /// </summary>
        private ContextManager()
        {
            _sync = new object();
        }


        /// <summary>
        /// Gets the singleton context manager instance
        /// </summary>
        /// <value>The instance.</value>
        public static ContextManager Instance
        {
            get { return _instance; }
        }
        #endregion


        #region api
        /// <summary>
        /// Initializes this instance.
        /// </summary>
        /// <remarks>
        /// Currently supports "School" and "Country" contexts.
        /// </remarks>
        /// <param name="contextToUse">The context to use.</param>
        public void Initialize(string contextToUse)
        {
            lock (_sync)
            {
                if (contextToUse.Equals("School", StringComparison.CurrentCultureIgnoreCase))
                {
                    _vm = new SchoolViewModel();
                    return;
                }
                _vm = new CountryViewModel();
            }
        }


        /// <summary>
        /// Retrieve the base view model (by name)
        /// </summary>
        /// <returns>
        /// the view model or null on error
        /// </returns>
        public BaseViewModel GetViewModel()
        {
            lock (_sync)
            {
                return _vm;
            }
        }
        #endregion
    }
}
